import requests
from sqlalchemy.orm import Session

from app.db.sql.resource import find_resource_by_resource_id
from common.log import get_logger

logger = get_logger('resource')

def send2resource(db: Session, resource_id: str, payload: dict):
    logger.info(f"send2resource: {resource_id}, {payload}")
    resource = find_resource_by_resource_id(db, resource_id)
    if resource is not None:
        res = requests.post(f"{resource.resource_host}/api/control", json=payload)
        return True

    return False
